<?
//Überprüfen ob der Abruf über die Hauptseite erfolgt
if(!defined('InStern')) exit;
echo "
<H1>$lang[reg_head]</h1>";

$error="";
$hide=false;
if(isset($_POST['do'])){
    $name=trim(strip_tags($_POST[name]));
    $email=trim(strip_tags($_POST[email]));
    if($db->num_rows($db->query("SELECT Id FROM user WHERE Name='".$db->real_escape_string($name)."';"))>0) $error=$lang[reg_error_userexists];
    else if($db->num_rows($db->query("SELECT Id FROM user WHERE Email='".$db->real_escape_string($email)."';"))>0) $error=$lang[reg_error_emailexists];
    else if(strlen($name)< 2) $error=$lang[reg_error_nametooshort];
    else if(!isset($_POST[agb])) $error=$lang[reg_error_agreements];
    else if(strlen($name)> 12) $error=$lang[reg_error_nametoolong];
    else if(!ereg("^[a-zA-Z0-9\ \-]*$", $_POST[name])) $error=$lang[reg_error_specialchars];
    else if(!ereg("[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+", $email)) $error=$lang[reg_error_emailnotvalid];
    else if(strlen($_POST[passwort1])< 6) $error=$lang[ref_error_passwordtooshort];
    else if($_POST[passwort1] != $_POST[passwort2]) $error=$lang[ref_errors_nopasswordmatch];
    else{
        //Scriptteil für die Registrierung
        $code=rand(111111,999999);
        $passwort=md5($_POST[passwort1]);
        $regdate=date(U);
        $db->query("INSERT INTO user(Name, Email, Passwort, Regdate, Code, Credits, Ref) VALUES('$name','$email','$passwort', $regdate, '$code', '$config_startcredits', '$ref');");
        echo $lang[reg_registrated];
        $mailtext="Hi $name,<br><br>";
        $mailtext.=$lang[reg_email_text1]."<br>";
        $mailtext.="<a href=\"http://$_SERVER[HTTP_HOST]/".$config_running_folder."index.php?cuser=$regdate&confirm=$code\">http://$_SERVER[HTTP_HOST]/".$config_running_folder."index.php?cuser=$regdate&confirm=$code</a> <br><br>";
        $mailtext.=$lang[reg_email_text2];
        require("class/mail.class.php");
	    $mail = new Mail(true);
	    $mail->setFrom("support@mixax.de");
	    $mail->setSubject($lang[reg_email_header]);
	    $mail->setBody($mailtext);
	    $mail->addRecipient($email);
	    $mail->setTemplate(file_get_contents("templates/email.html"));
	    $mail->send();
		    
		    $hide=true;
    }
}
if(!$hide){
    echo $lang[reg_desc];
    if($error!="") echo "<div class=\"error\">$error</div>";
    echo "
    <form action=\"$_SERVER[PHP_SELF]\" method=\"post\">
      <table align=\"center\">
        <tr>
          <td align=\"right\">".$lang[reg_login].":</td>
          <td><input type=\"text\" name=\"name\" maxlength=\"12\" value=\"$_POST[name]\" /></td>
        </tr>
        <tr>
          <td align=\"right\">".$lang[reg_email].":</td>
          <td><input type=\"text\" name=\"email\" value=\"$_POST[email]\" /></td>
        </tr>
        <tr>
          <td align=\"right\">".$lang[reg_password].":</td>
          <td><input type=\"password\" name=\"passwort1\"/></td>
        </tr>
        <tr>
          <td align=\"right\">".$lang[reg_password].":<br><font style=\"font-size:8px\">(".$lang[reg_repeat].")</font></td>
          <td><input type=\"password\" name=\"passwort2\"/></td>
        </tr>
        <tr>
          <td colspan=\"2\">
          <div style=\"width:600px; height:200px; overflow:scroll; border:1px solid black;\">";
          include("lang/$_SESSION[lang]/agb.lang.php");
          echo "
          </div>
          <input type=\"checkbox\" name=\"agb\" />".$lang[reg_ack]."</td>
        </tr>
        <tr>
        <th colspan=\"2\"><input type=\"submit\" value=\"".$lang[reg_register]."\" name=\"do\" /></th>
      </tr>
     </table>
	</form>";
}
?>